package com.ysm.smfu.welcome;

import android.content.Context;
import android.content.SharedPreferences;

import com.ysm.smfu.contans.SpKey;

//获得软件的全局配置文件
public class SharedConfig {
    Context context;
    SharedPreferences shared;
    SharedPreferences currShared;

    public SharedConfig(Context context) {
        this.context = context;
        shared = context.getSharedPreferences("config", Context.MODE_PRIVATE);
    }

    public SharedConfig(Context context, String currName) {
        currShared = context.getSharedPreferences("sp" + currName, Context.MODE_PRIVATE);
    }

    /**
     * 存储公共信息
     *
     * @param key
     * @param value
     */
    public void saveCommoneStringInfo(String key, String value) {
        shared.edit().putString(key, value).apply();
    }

    public void saveCommoneBooleanInfo(String key, boolean value) {
        shared.edit().putBoolean(key, value).apply();
    }

    public boolean getCommoneBooleanInfo(String key) {
        return shared.getBoolean(key, true);
    }

    /**
     * 返回公共信息
     *
     * @param key
     * @return
     */
    public String getCommoneStringInfo(String key) {
        return shared.getString(key, "");
    }

    /**
     * 存储用户信息
     *
     * @param key
     * @param value
     */
    public void savePrivateInfo(String key, String value) {
        currShared.edit().putString(key, value).apply();
    }

    /**
     * 返回用户信息
     *
     * @param key
     * @return
     */
    public String getPrivateInfo(String key) {
        return currShared.getString(key, "");
    }


    public SharedPreferences getCommoneSp() {
        return shared;
    }

    public SharedPreferences getPrivateSp() {
        return currShared;
    }

    public void ClearConfig() {
        shared.edit().clear().commit();
    }

}
